package com.gid.rcflightlogger;


import java.util.Date;

import android.content.Context;

import com.orm.androrm.BooleanField;
import com.orm.androrm.CharField;
import com.orm.androrm.DateField;
import com.orm.androrm.DoubleField;
import com.orm.androrm.Model;
import com.orm.androrm.OneToManyField;
import com.orm.androrm.QuerySet;

public class Battery extends Model {
	
	public static final QuerySet<Battery> objects(Context context) {
		return objects(context, Battery.class);
	}

	public static final int NAME_LEN = 18;
	public static final int TAG_LEN = 8;
	public static final String[] TYPE_ARRAY = {"LiPo", "NiMH", "LiFe", "Other"};
	public static final String ID_LABEL = "BatteryID"; //used for passing/saving states

	
	protected CharField mType;
	protected CharField mName;
	protected CharField mTag;
	protected DoubleField mCost;
	protected DateField mPurchaseDate; //YYYY-MM-DDTHH:MM:SS
	protected DateField mRegisterDate;
	protected BooleanField mStatus;
	protected CharField mNotes;
	protected OneToManyField<Battery, Cycle> mCyles;
	
	//constructor
	public Battery() {
		super();
		
		mType = new CharField();
		mName = new CharField(NAME_LEN);
		mTag = new CharField(TAG_LEN);
		mCost = new DoubleField();
		mPurchaseDate = new DateField();
		mRegisterDate = new DateField();
		mStatus = new BooleanField();
		mNotes = new CharField();
		mCyles = new OneToManyField<Battery, Cycle>(Battery.class, Cycle.class);
		reset();
	}
	
	//reset all fields to default value
	public void reset()
	{
		mType.set(TYPE_ARRAY[0]);
		mName.set("");
		mCost.set(0.0);
		Date current_date = new Date();
		mPurchaseDate.set(current_date);
		mRegisterDate.set(current_date);
		mStatus.set(true);
		mNotes.set("");
	}

	//member access methods
	public String getType() {
		return mType.get();
	}
	
	public void setType(String type) {
		mType.set(type);
	}
	
	public String getName() {
		return mName.get();
	}
	
	public void setName(String name) {
		
		mName.set(name);
	}
	
	public String getTag() {
		return mTag.get();
	}
	
	public void setTag(String tag) {
		
		mTag.set(tag);
	}
	
	public double getCost()
	{
		return mCost.get();
	}
	
	public void setCost(double cost) {
		mCost.set(cost);
	}
	
	public Date getPurchaseDate() {
		return mPurchaseDate.get();
	}
	
	public void setPurchaseDate(Date date) {
		mPurchaseDate.set(date);
	}
	
	public Date getRegisterDate() {
		return mRegisterDate.get();
	}
	
	public void setRegisterDate(Date d) {
		mRegisterDate.set(d);
	}
	
	public boolean getStatus() {
		return mStatus.get();
	}
	
	public void setStatus(boolean status) {
		mStatus.set(status);
	}
	
	public QuerySet<Cycle> getCycles(Context context) {
		return mCyles.get(context, this);
	}
	
	public String getNotes() {
		return mNotes.get();
	}
	
	public void setNotes(String notes) {
		
		mNotes.set(notes);
	}
	
	public String toString()
	{
		String res = mTag.get();
		String name = mName.get();
		if (name.length() != 0)
			res = res + " (" + name + ")";
		return res;
	}
}
